require(['../config/requireconfig'],function(config){
	//根据需要添加
	require(['jquery','common/pccommons',"common/prodgen","vendor/autocomplete"],function($,com,gener,autocomplete){
		
         com.init({headerPos:{menu:2,sub:2}});
		var pageLogic = new PageLogic($,com,gener);
		pageLogic.init();

	});
});
var PageLogic = function($,com,gener){
	return{
		init:function(){
			var _this = this;
			_this.loadParts();
		},
		loadParts:function(){
			var _this = this;
			com.ajax({
				url:"/queryPartNumberList.json",
				success:function(res){
					var proposals =[];
					$(res).each(function(idx,obj){
						if(obj){
							proposals[idx]=obj;	
						}
					})
					_this.enableTypeHead(proposals);
				}
			});
		},
		enableTypeHead:function(assets){
			var _this = this;
			var allSize = MediaSize.widthFontsize() * 42;
			var btnSize = MediaSize.widthFontsize() * 8.75;
			$('#search-form').autocomplete({
                hints: assets,
                width: allSize,
                height: 40,
                btnwidth:btnSize,
                buttonText:'零件号查询',
                mustMatch: true,
                onSubmit: function(text){
	            	_this.cleartPartInfo();
	            	_this.loadPartInfo(text);
		        }
		    });
		},
		loadPartInfo:function(partObj){
			var _this = this;
			var dataObj = {};
			if(!partObj){
				return;
			}
			dataObj["vehicleNo"]=partObj;
			com.ajax({
				url:"/getPartNumber.json",
				data:dataObj,
				success:function(res){
					if(res.success){
						// 查询结果
						if(!res.data.resList || res.data.resList.length == 0){
							alert("没有此零件信息");
							$(".search-con").html("");
							return;
						}
						_this.resInfo(res.data.resList);
						gener.prdRemark($(".search-con"),res.data.desList,res.data.desList1,res.data.lj);
						gener.paramInfo($(".search-con"),res.data.partList);
						gener.carInfo($(".search-con"),res.data.selectVehicleNoByPart);
					}
				}
			})
		},
		cleartPartInfo:function(){
			$(".search-con").html("");
		},
		genPartInfoTable:function(partInfo){
			var html = "";

		},
		// 查询结果
		resInfo:function(resList){
			var html = "";
			var trs = "";
			var ths = "";
			html +='<div class="search-con-item">';
			html +='	<div class="search-con-item-title">查询结果</div>';
			html +='	<div class="dk-table">';
			html +='	  <table>';
			html +='		<thead>';
			$(resList).each(function(){
				trs += "<tr>";
				trs += "<td>" + this.PART_NUMBER +"</td>";
				trs += "<td>" + this.PART_NAME_CN +"</td>";
				trs += "<td>" + this.prodLine +"</td>";
				$(this.value).each(function(){
					trs += "<td>" + this + "</td>";
				})
				if(!ths){
					$(this.name).each(function(){
						ths += "<th>" + this + "</th>";	
					})
				}
				trs += "</tr>";
			});
			html += '<tr><th width="20%">零件号</th><th width="20%">零件名称</th><th width="20%">产品系列</th>' + ths + "</tr>";
			html +='		</thead>';
			html +='		<tbody>';
			html += trs;
			html += '       </tbody>';
			html += '       </table>';
			html += '   </div>';
			html += '</div>';
			$(".search-con").append(html);
		},
		
		

	}
}